//
// ZCAspect.h
// Copyright 2010 Mark Buer
//
// This file is part of zc-aspect.
//
// zc-aspect is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// zc-aspect is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with zc-aspect.  If not, see <http://www.gnu.org/licenses/>.
//

#import <Foundation/Foundation.h>
#import <objc/objc-class.h>

@protocol ZCInterceptor;


typedef enum {
	RRTVoid, RRTStruct, RRTScaler32, RRTScaler64, RRTFloat32, RRTFloat64, RRTFloat128
} RoughReturnType;


typedef struct {
	IMP previousImplementation;
	id <ZCInterceptor> interceptor;
	int frameSize;
	RoughReturnType roughReturnType;
} InterceptionDescriptor;


typedef struct {
	void *stackFrameBase;
	InterceptionDescriptor *interceptionDescriptor;
	union {
		char c;
		int i;
		short s;
		long l;
		long long q;
		unsigned char C;
		unsigned int I;
		unsigned short S;
		unsigned long L;
		unsigned long long Q;
		float f;
		double d;
		long double D;
		_Bool B;
		void *p;
		
		uint32_t scaler32;
		uint64_t scaler64;
		float float32;
		double float64;
		long double float128;
		
	} returnValue;
} Invocation;


void invocation_invoke(Invocation *invocation);


// Needs documenting
@protocol ZCInterceptor <NSObject>

- (void)interceptInvocation:(Invocation *)invocation;

@end


// Needs documenting
@interface ZCInterceptionManager : NSObject {
	
}

+ (void)watchClass:(Class)theClass withInterceptor:(id <ZCInterceptor>)interceptor excludingSelectors:(NSArray *)selectorsToExclude;
+ (void)interceptMethod:(Method)method withInterceptor:(id <ZCInterceptor>)interceptor;

@end
